<template>
	<view class="junxiao">
		<view class="header">
			<uniNavBar title="军校"></uniNavBar>
		</view>
		<view class="content">
			<view class="list-item" v-for="(item, i) in junxiaoData" :key="`junxiao-${i}`">
				<view class="t-time">
					{{item.createTime}}
				</view>
				<view class="item-content" @tap="junxiaoDetail(item)">
					<image mode="aspectFill" class="item-img" :src="`https://static.xpandago.net/${item.picture}`"></image>
					<text class="item-title">{{item.title}}</text>
					<view>
						<text class="item-description">{{item.description}}</text>
					</view>
				</view>
			</view>
			<view class="default-Page" v-show="!junxiaoData.length">
				<image src="/static/h5img/default_04@2x.png" class="default4"></image>
			</view>
		</view>
	</view>
</template>

<script>
	import api from '@/common/api';
	import uniNavBar from "@/components/uni-nav-bar/uni-nav-bar.vue" 
	import { ifLogin } from '@/common/js/index'
	export default {
		data() {
			return {
				junxiaoData: [],
				token: '',
			}
		},
		methods: {	
			// 请求军校列表
			async getList() {
				const _this = this
				_this.token=uni.getStorageSync('token')
				const [err, res] = await api.schoolList({
					method:'get',
					header:{
						'Content-Type': 'application/json;charset=UTF-8',
						'token': _this.token,
					},
				})
				console.log(res,err)
				if (res) {
					const { data = {} } = res
					if (data.code === 0 && data.data && data.data.list ){
						_this.junxiaoData = data.data.list
					}
				}
				console.log(err,res)
			},
			junxiaoDetail({url = '',schoolId}) {
				if (url) {
					window.open(url,'_self')
				} else {
					// 没有url跳转到详情页面
					uni.navigateTo({
						url:`/pages/schoolDetail/schoolDetail?schoolId=${schoolId}`
					})
				}
			}
		},
		components: {
			uniNavBar
		},
		onLoad() {
			const status = ifLogin()
			if (status) {
				this.getList()
			}
		}
	}
</script>

<style scoped lang="scss">
	body, uni-page-body{
		background-color: #f6f6f6;
	}
	.junxiao{
		background-color: #f6f6f6;
		height: 100%;
		.header{
			position: fixed;
			width: 100%;
			z-index: 10;
		}
		.content{
			padding: 0 30rpx 40rpx 30rpx;
			box-sizing: border-box;
			height: 100%;
			&::before{
				content: '';
				height: 44px;
				display: block;
			}
			.default-Page{
				height: 100%;
				width: 100%;
				display: flex;
				justify-content: center;
				align-items: center;
				.default4{
					height: 560rpx;
					width: 440rpx;
					margin-top: 80rpx;
				}
			}
			.list-item{
				margin-top: 30rpx;
				.t-time{
					height: 42rpx;
					line-height: 42rpx;
					border-radius:4rpx;
					background-color: #ddd;
					width: fit-content;
					margin: 0 auto;
					color: #fff;
					padding: 0 14rpx;
					font-size: 24rpx;
					font-family: PingFang-SC-Medium;
				}
			}
			.item-content{
				padding: 22rpx 30rpx;
				margin-top: 26rpx;
				background-color: #fff;
				border-radius: 12rpx;
				.item-img{
					width: 100%;
					height: 280rpx;
				}
				.item-title{
					font-size:30rpx;
					font-family:PingFang SC;
					font-weight:bold;
					color: #353526;
					line-height:34rpx;
					margin-top: 22rpx;
					word-break: break-all;
				}
				.item-description{
					margin-top: 12rpx;
					font-size:24rpx;
					font-family:PingFang SC;
					color: #353526;
					word-break: break-all;
				}
			}
		}
	}
</style>
